//
//  HMMainViewController.swift
//  weibo28
//
//  Created by 范英强 on 16/3/23.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = HMTabBar()
        tabBar.hmDelegate = self
        // 系统tabBar是只读属性
        //self.tabBar = tabBar
        
        // KVC 
        self.setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(HMHomeTableViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(HMMessageTableViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(HMDiscoverTableViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(HMProfileTableViewController(), title: "我", imgName: "tabbar_profile")
    }
    /**
     添加子控制器
     
     - parameter vc:      vc
     - parameter title:   title
     - parameter imgName: imgName
     */
    func addChildViewController(vc: UIViewController, title: String, imgName: String){
        
        // 设置title
        vc.title = title
//        vc.navigationItem.title = title
//        vc.tabBarItem.title = title
        // 设置图片
        vc.tabBarItem.image = UIImage(named: imgName)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        
       // let nav = UINavigationController(rootViewController: vc)
        
        // 添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }
    

}

extension HMMainViewController:HMTabBarDelegate{
    func composeButtonClick() {
        print("撰写按钮被点击啦")
    }
}


